package com.whfc.ms.api.emp.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.ListData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.emp.dto.*;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.emp.service.MsAppEmpIndexService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 人员首页相关的接口
 *
 * @author guodong_sun
 * @Description:
 * @date 2019年7月23日
 */
@RequiresPermissions("emp/index")
@RestController
@RequestMapping("/ms/api/index")
public class AppEmpIndexController extends BaseController {

    @Autowired
    private MsAppEmpIndexService msAppEmpIndexService;

    /**
     * 获取可供选择的工种或者岗位
     *
     * @param user
     * @return
     */
    @GetMapping("/getWorkTypeList")
    public Result getWorkTypeList(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @RequestParam("deptId") Integer deptId) {
        logger.info("获取可供选择的工种或者岗位。loginer:{}", user.getUsername());
        ListData<AppWorkTypeDTO> listData = msAppEmpIndexService.getWorkTypeList(deptId);
        return ResultUtil.success(listData);
    }

    /**
     * 首页获取人员详细信息
     *
     * @param user
     * @param empId
     * @return
     */
    @GetMapping("/getEmpDetail")
    public Result getEmpDetail(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @RequestParam("empId") Integer empId) {
        logger.info("首页获取人员详细信息，loginer:{},empId:{}", user.getUsername(), empId);
        AppEmpDetailDTO appEmpDetailDTO = msAppEmpIndexService.getEmpDetail(empId);
        return ResultUtil.success(appEmpDetailDTO);
    }


    @GetMapping("/getMapEmpList")
    public Result getMapEmpList(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                @RequestParam("deptId") Integer deptId,
                                @RequestParam(value = "groupId", required = false) Integer groupId,
                                @RequestParam(value = "empName", required = false) String empName) {
        logger.info("获取地图人员列表,loginer:{},deptId:{},groupId：{}，empName:{}", user.getUsername(), deptId, groupId, empName);
        ListData<AppEmpDTO> listData = msAppEmpIndexService.getMapEmpList(deptId, groupId, empName);
        return ResultUtil.success(listData);
    }

    @GetMapping("/getMapEmpPoly")
    public Result getMapEmpPoly(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                @RequestParam("deptId") Integer deptId,
                                @RequestParam(value = "groupId", required = false) Integer groupId,
                                @RequestParam(value = "empName", required = false) String empName,
                                @RequestParam(value = "fenceId", required = false) Integer fenceId) {
        logger.info("获取地图人员聚合,loginer:{},deptId:{},groupId：{}，empName:{},fenceId:{}",
                user.getUsername(), deptId, groupId, empName, fenceId);
        ListData<MapEmpPolyDTO> listData = msAppEmpIndexService.getMapEmpPoly(deptId, groupId, empName, fenceId);
        return ResultUtil.success(listData);
    }

    @GetMapping("/fvs/tab")
    public Result getIndexTab(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                              @RequestParam("deptId") Integer deptId) {
        logger.info("获取地图人员聚合,loginer:{}, deptId:{}", user.getUsername(), deptId);
        boolean indexFvsTab = msAppEmpIndexService.getIndexFvsTab(deptId);
        return ResultUtil.success(indexFvsTab);
    }


    @GetMapping("/getMapEmpFvs")
    public Result getMapEmpFvs(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                               @RequestParam("deptId") Integer deptId,
                               @RequestParam(value = "groupId", required = false) Integer groupId,
                               @RequestParam(value = "empName", required = false) String empName,
                               @RequestParam(value = "fvsDeviceId", required = false) Integer fvsDeviceId) {
        logger.info("地图人员列表（班组视频监控),loginer:{},deptId:{},groupId：{}，empName:{},fvsDeviceId:{}",
                user.getUsername(), deptId, groupId, empName, fvsDeviceId);
        ListData<MapEmpGroupDTO> listData = msAppEmpIndexService.getMapEmpFvs(deptId, groupId, empName, fvsDeviceId);
        return ResultUtil.success(listData);
    }


}
